/*Author Rajith Chathunga,
 *		 Computer Science and Engineering,
 *		 University of Moratuwa.
 *
 * Class name : CricNews
 * 
 *  			
 * This class store cricket countries and their cricket rss URLs and send them to the QNews class. 
 * This class extends Activity and implements onClickListener.*/

package chathunga.qNews;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

public class CricNews extends Activity implements OnClickListener {
	ListView lv1;
	NewsObjects no;
	String ss,t1,u1;
	TextView optn;
	ImageView img;
	Bundle b = new Bundle();
	private ArrayList<Object> cricnews=new ArrayList<Object>();
	
	public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.cricnews); 
        lv1=(ListView)findViewById(R.id.criccon);
        optn=(TextView)findViewById(R.id.addnh);
        img=(ImageView)findViewById(R.id.qn);
        img.setOnClickListener(this);
        optn.setOnClickListener(this);
        data();
        
        
        
        lv1.setAdapter(new ArrayAdapter<Object>(this,R.layout.list_black_text,R.id.list_content , cricnews));
        lv1.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
            long arg3) {
            Toast.makeText(getBaseContext(), ""+cricnews.get(arg2), Toast.LENGTH_LONG).show();
            
            no=(NewsObjects) cricnews.get(arg2);
            ss=no.toStr();
            operation();
                       
    	}
            });
        
        
        
	}
	//This method contains cricket countries and rss URLs in an ArrayList
	public void data(){
		cricnews.add(new NewsObjects("International","http://www.espncricinfo.com/rss/content/feeds/news/5.xml"));
        cricnews.add(new NewsObjects("Australia","http://www.espncricinfo.com/rss/content/story/feeds/2.xml"));
        cricnews.add(new NewsObjects("India","http://www.espncricinfo.com/rss/content/story/feeds/6.xml"));
        cricnews.add(new NewsObjects("Sri Lanka","http://www.espncricinfo.com/rss/content/story/feeds/8.xml"));
        cricnews.add(new NewsObjects("South Africa","http://www.espncricinfo.com/rss/content/story/feeds/3.xml"));
        cricnews.add(new NewsObjects("England","http://www.espncricinfo.com/rss/content/story/feeds/3.xml"));
        cricnews.add(new NewsObjects("Pakistan","http://www.espncricinfo.com/rss/content/story/feeds/7.xml"));
        cricnews.add(new NewsObjects("West Indies","http://www.espncricinfo.com/rss/content/story/feeds/4.xml"));
        cricnews.add(new NewsObjects("New Zealand","http://www.espncricinfo.com/rss/content/feeds/news/5.xml"));
	}
	//This method is called when click on a cricket country.
	public void operation(){
		
		Intent it= new Intent(this,QNews.class);	

		b.putString("key", ss);

		it.putExtras(b);

		startActivity(it);
	}
	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		if(v.getId()==R.id.qn){
			
			this.finish();
			
			Intent bToHome= new Intent(this,MainQNews.class);
			
			startActivity(bToHome);
			
			finish();
		}
		if(v.getId()==R.id.addnh){
			
			Intent it= new Intent(this,Option.class);
			
			startActivity(it);
		}
	}

}
